<?php

namespace App\Providers;

use App\Repository\Models\User;
use Illuminate\Routing\Router;
use Illuminate\Support\ServiceProvider;

class RouteServiceProvider extends ServiceProvider
{
    /**
     * This namespace is applied to the controller routes in your routes file.
     *
     * In addition, it is set as the URL generator's root namespace.
     *
     * @var string
     */
    protected $namespace = 'App\Http\Controllers';

    /**
     * Define your route model bindings, pattern filters, etc.
     *
     * @param  \Illuminate\Routing\Router  $router
     * @return void
     */
    public function boot(Router $router)
    {
        /*
         * 配置前后台认证的模型
         */
        $uri = array_get($_SERVER,'REQUEST_URI');
        $pathInfo = array_filter(explode('/', $uri), function ($v, $k) {
            return $v != '';
        }, ARRAY_FILTER_USE_BOTH);
        $pathInfo = array_values($pathInfo);
        if(count($pathInfo) && $pathInfo[0] == 'backend'){
            config(['jwt.user' => '\App\Repository\Models\AdminUser']);
            config(['auth.providers.users.model' => \App\Repository\Models\AdminUser::class]);
            config(['auth.model' => \App\Repository\Models\AdminUser::class]);
        }else{
            config(['jwt.user' => User::class]);
            config(['auth.providers.users.model' => User::class]);
            config(['auth.model' => User::class]);
        }

        $this->app->router->group([
            'namespace' => 'App\Http\Controllers\Web',
            'prefix' => 'web',
        ], function ($router) {
            require base_path('/routes/web.php');
        });

        /*
         * 后台路由模块
         */
        $this->app->router->group([
            'namespace' => 'App\Http\Controllers\Backend',
            'prefix' => 'backend',
        ], function ($router) {
            require base_path('/routes/backend.php');
        });

        $this->app->router->group([
            'namespace' => 'App\Http\Controllers\User',
        ], function ($router) {
            require base_path('/routes/user.php');
        });

        $this->app->router->group([
            'namespace' => 'App\Http\Controllers\Wap',
            'prefix' => 'wap',
        ], function ($router) {
            require base_path('/routes/wap.php');
        });

    }
    
}
